//base
import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
//less
import './index.less'

class ChooseBar extends Component {
  state = {
    datasource: [{ name: '公司介绍' }]
    // datasource: [{name: '公司介绍'}, {name: '热招职位'}]
  }

  componentWillMount() {
    //onLoad
  }

  componentDidMount() {
    //onready
  }

  componentDidShow() {
    //onshow
  }

  componentDidHide() {
    //onhide
  }

  componentWillUnmount() {
    //onUnload
  }

  delay(time = 0) {
    return new Promise(resolve => {
      setTimeout(() => {
        resolve()
      }, time)
    })
  }

  handchange = index => {
    this.props.onUpdateState({
      choosecurrent: index
    })
  }

  render() {
    return (
      <View className="ChooseBar_id78263">
        {this.state.datasource.map((data, index) => {
          return (
            <View
              onClick={this.handchange.bind(this, index)}
              className={`choosebarsingle ${
                index == this.props.current ? 'choosebarsingleact' : ''
              }`}
            >
              {data.name}
              {index == 1 ? `(${this.props.jobcount || 0})` : ''}
            </View>
          )
        })}
      </View>
    )
  }
}

export default ChooseBar
